var o={
	publicKey : 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCR4nOCkGnBwUcQPzXCYnQwQ2+IXwkTkGDc3WyU8eAlV/jQTO2LGv0JECewGr2g+DetnwAfvHgv4HH3NCAgbK2yUnOpQPSaMZIUMNCWatoNTsZm0WOn3XQtreQdAWgskPflxU5oJs9IUErmHoXzs2aVxozizJPazLIKKttdz5PJlwIDAQAB',
	/**
	 * MD5加密算法
	 * @param plantText 明文
	 * @returns string 密文
	 */
	EncryptByMD5: function(srting){
        return $.md5(srting)
    },
    /**
	 * 创建一个16位长度的AES密钥，格式为：当前时间13位毫秒值 + 3位随机数
	 * @returns AES密钥，例如:'1501073000000365'
	 */
    CreateKeyOfAES: function(){
        return Date.parse(new Date()) + Math.random().toString().substr(2,3);
    },
    /**
	 * AES加密算法
	 * @param plantText 明文
	 * @param keyText 密钥，固定长度为16位，例如：'0102030405060708'
	 * @returns string 密文
	 */
    EncryptByAES: function(plantText,keyText){
        const key = CryptoJS.enc.Utf8.parse(keyText);
        const iv = CryptoJS.enc.Utf8.parse(keyText);
        const srcs = CryptoJS.enc.Utf8.parse(plantText);
        const encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC });
        return encrypted.toString();
    },
    /**
	 * RSA加密算法
	 * @param plantText 明文
	 * @returns string 密文
	 */
    EncryptByRSA: function(plantText){
        const encrypt = new JSEncrypt();
        encrypt.setPublicKey(this.publicKey);
        return encrypt.encrypt(plantText);
    }
};
(function(){
	  window['my'] = {};
	  function sPost(url,data,callback){
	        const key = o.CreateKeyOfAES();
	        var paramJsonStr = JSON.stringify(data);
	        if (null === data || undefined === data || '' === data) {
	            paramJsonStr = ''
	        }
	        const encryptedParam = o.EncryptByAES(paramJsonStr, key);
	        const keyOfRSA = o.EncryptByRSA(key);
	        return axios.post(url,
	            JSON.stringify({
	                    params : encryptedParam,
	                    key : keyOfRSA,
	                    sign : o.EncryptByMD5(url + keyOfRSA + encryptedParam)
	                })
	            ).then(res => {
	                callback(res);
	            })
	    }
	  window['my']['sPost'] = sPost;
})();
